home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 2661 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: news.NetVision.net.il!news
  2. From: Boazs@spl.co.il (Boaz Sdeor)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Can't figure this out
  5. Date: Mon, 22 Jan 1996 22:14:08 GMT
  6. Organization: NetVision LTD.
  7. Message-ID: <4e12rt$hnb@news.NetVision.net.il>
  8. References: <31000091.3778302@news.panix.com>
  9. NNTP-Posting-Host: ts3qp15.netvision.net.il
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. dm@panix.com (Dan'l) wrote:
  13.  
  14. >I am learning C and I have not had any problems understanding most
  15. >concepts I have learned so far.  But to date I still can't figure out
  16. >how the outcome of this program is 15.  Somehow one of the B's ends up
  17. >a three and the other B a 5, or am I so off base that I can't see
  18. >what's really happening.    Can someone please walk me through this
  19. >one.                                             Thanks     Dan'l
  20.  
  21. >#define A 3
  22. >#define B A + A
  23. >#define C B * B
  24.  
  25. >main()
  26. >{
  27. >    printf("%d", C);
  28. >    return 0;
  29. >}
  30. Substitute B * B for C, and then A + A for B, you get :
  31.  
  32. C  -->  A + A * A + A  (no parethesis !), hence C = 3 + 3 * 3 + 3 =
  33.            3 + 9 + 3 = 15 !
  34.  
  35. to get the correct answer, always use () in the #define , e.g.
  36. #define  C (B) * (B) - and the problem disappears.
  37.  
  38. Boaz.
  39.  
  40.